package com.example.teachingSystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.teachingSystem.mapper.PermissionMapper;
import com.example.teachingSystem.pojo.entity.Permission;
import com.example.teachingSystem.service.PermissionService;
import com.example.teachingSystem.utils.result.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86147
 * @description 针对表【permission(权限表)】的数据库操作Service实现
 * @createDate 2023-11-27 21:43:54
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission>
        implements PermissionService {

    @Override
    public Result<String> changePermToClose(Long id){
        this.update(new LambdaUpdateWrapper<Permission>()
                .eq(Permission::getPermissionId,id).set(Permission::getStatus,false));
        return Result.ok(null,"成功关闭权限");
    }

    @Override
    public Result<String> changePermToOpen(Long id){
        this.update(new LambdaUpdateWrapper<Permission>()
                .eq(Permission::getPermissionId,id).set(Permission::getStatus,true));
        return Result.ok(null,"成功开放权限");
    }

    @Override
    public Result<List<Permission>> getPermission(){
        List<Permission> permissions = this.list();
        return Result.ok(permissions);
    }

}




